home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 41
/
Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso
/
Aminet
/
comm
/
misc
/
MPackMUI.lha
/
MPackMUI
/
Source
/
ProgFuncs.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-08-23
|
5KB
|
258 lines
// --------------------------------------------------------------------------------------------------------------
//
// MPackMUI V1.01 Program Module
//
// --------------------------------------------------------------------------------------------------------------
#include "ProgFuncs.h"
// --------------------------------------------------------------------------------------------------------------
void FreeList(struct List *list)
{
struct Node *tempnode, *nextnode;
// Frees all the nodes and their names in a given list
if (!(IsListEmpty(list)))
{
tempnode = list->lh_Head;
while (tempnode->ln_Succ)
{
nextnode = tempnode->ln_Succ;
FreeMem(tempnode->ln_Name, 256);
FreeMem(tempnode, sizeof(struct Node));
tempnode = nextnode;
} /* while */
} /* if */
} /* FreeList() */
// --------------------------------------------------------------------------------------------------------------
void DefaultMIMEList()
{
UBYTE loop;
struct Node *tempnode;
// Initialise the MIME types list with default values
NewList(&MIMEList);
loop = 0;
while(DefaultMIMETypes[loop] != NULL)
{
if (!(tempnode = AllocMem(sizeof(struct Node), 0)))
{
DoEasyReq("Couldn't allocate node");
CleanUp();
} /* if */
if (!(tempnode->ln_Name = AllocMem(256, 0)))
{
DoEasyReq("Couldn't allocate label");
CleanUp();
} /* if */
strcpy(tempnode->ln_Name, DefaultMIMETypes[loop]);
AddTail(&MIMEList, tempnode);
loop++;
} /* while */
// Rebuild the MIME types array from the MIME types list
RebuildMIMETypes();
} /* DefaultMIMEList() */
// --------------------------------------------------------------------------------------------------------------
void RebuildMIMETypes()
{
UWORD loop;
struct Node *tempnode;
// Rebuild the MIME types array from the MIME types list
// Free old array
loop = 0;
while (MIMETypes[loop])
{
FreeMem(MIMETypes[loop], 256);
loop++;
} /* while */
// Build new array
loop = 0;
if (!(IsListEmpty(&MIMEList)))
{
tempnode = MIMEList.lh_Head;
while (tempnode->ln_Succ)
{
if (!(MIMETypes[loop] = AllocMem(256, 0)))
{
DoEasyReq("Couldn't allocate label");
CleanUp();
} /* if */
strcpy(MIMETypes[loop], tempnode->ln_Name);
loop++;
tempnode = tempnode->ln_Succ;
} /* while */
} /* if */
MIMETypes[loop] = NULL;
} /* RebuildMIMETypes() */
// --------------------------------------------------------------------------------------------------------------
void RebuildMIMEList()
{
struct Node *tempnode;
UWORD loop;
// Rebuild the MIME types list from the MIME types array
// Free old list
FreeList(&MIMEList);
// Build new list
NewList(&MIMEList);
loop = 0;
while (MIMETypes[loop])
{
// Create a new node
if (!(tempnode = AllocMem(sizeof(struct Node), 0)))
{
DoEasyReq("Couldn't allocate node");
CleanUp();
} /* if */
if (!(tempnode->ln_Name = AllocMem(256, 0)))
{
DoEasyReq("Couldn't allocate label");
CleanUp();
} /* if */
strcpy(tempnode->ln_Name, MIMETypes[loop]);
AddTail(&MIMEList, tempnode);
loop++;
} /* while */
} /* RebuildMIMEList() */
// --------------------------------------------------------------------------------------------------------------
void OpenPrefs(char *filename)
{
BPTR prefsfile;
char buffer[256];
UWORD loop;
// Open MIME types file
if (!(prefsfile = Open(filename, MODE_OLDFILE)))
{
// No prefs file. Use defaults
DefaultMIMEList();
return;
} /* if */
// Free old array
loop = 0;
while (MIMETypes[loop])
{
FreeMem(MIMETypes[loop], 256);
loop++;
} /* while */
// Build new array
loop = 0;
while (FGets(prefsfile, buffer, 256))
{
// Add an entry to the array
if (!(MIMETypes[loop] = AllocMem(256, 0)))
{
DoEasyReq("Couldn't allocate label");
CleanUp();
} /* if */
// Remove newline
buffer[strlen(buffer) - 1] = '\0';
strcpy(MIMETypes[loop], buffer);
loop++;
} /* while */
Close(prefsfile);
MIMETypes[loop] = NULL;
// Rebuild the MIME types list from the MIME types array
NewList(&MIMEList);
RebuildMIMEList();
return;
} /* OpenPrefs() */
// --------------------------------------------------------------------------------------------------------------
void SavePrefs(char *filename)
{
BPTR prefsfile;
UWORD loop;
// Save MIME types to a file
if (!(prefsfile = Open(filename, MODE_NEWFILE)))
{
DoEasyReq("Could't save prefs");
return;
} /* if */
loop = 0;
while (MIMETypes[loop])
{
FPuts(prefsfile, MIMETypes[loop]);
FPutC(prefsfile, '\n');
loop++;
} /* while */
Close(prefsfile);
} /* SavePrefs() */
// --------------------------------------------------------------------------------------------------------------
// End Of Text